package io.renren.modules.substation.service.impl;

import io.renren.modules.substation.entity.TInfoAreaInfoEntity;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.substation.dao.TBusiAreaHotInfoDao;
import io.renren.modules.substation.entity.TBusiAreaHotInfoEntity;
import io.renren.modules.substation.service.TBusiAreaHotInfoService;


@Service("tBusiAreaHotInfoService")
public class TBusiAreaHotInfoServiceImpl extends ServiceImpl<TBusiAreaHotInfoDao, TBusiAreaHotInfoEntity> implements TBusiAreaHotInfoService {
    @Autowired
    private TInfoRoleAreaServiceImpl tInfoRoleAreaServiceImpl;

    protected SysUserEntity getUser() {
        return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        List<Long> areaList = tInfoRoleAreaServiceImpl.getAreaListByUser(getUser().getUserId());
        String devCode = params.containsKey("devCode") ? params.get("devCode").toString() : null;
        String hotType = params.containsKey("hotType") ? params.get("hotType").toString() : null;
        IPage<TBusiAreaHotInfoEntity> page = this.page(
                new Query<TBusiAreaHotInfoEntity>().getPage(params),
                new QueryWrapper<TBusiAreaHotInfoEntity>()
                .in(areaList != null && areaList.size() > 0, "AREA_ID", areaList)
                .eq(hotType != null && !hotType.equals(""), "HOT_TYPE", hotType)
                .eq(devCode != null && !devCode.equals(""), "DEV_CODE", devCode)
        );

        return new PageUtils(page);
    }

    @Override
    public List<TBusiAreaHotInfoEntity> getAreaHotInfoByArea(Long areaId) {
        List<TBusiAreaHotInfoEntity> list = baseMapper.selectList(
                new QueryWrapper<TBusiAreaHotInfoEntity>().
                        eq(areaId != null,"AREA_ID", areaId)
            );
        return list;
    }

}